//
//  WPMineInfomationCell.m
//  wobingwoyi
//
//  Created by WGP on 16/9/7.
//  Copyright © 2016年 WGP. All rights reserved.
//

#import "WPMineInfomationCell.h"

@interface WPMineInfomationCell ()

@property(nonatomic,strong)UIImageView *iconView;
@property(nonatomic,strong)UILabel *redPointLabel;
@property(nonatomic,strong)UILabel *titleLabel;
@property(nonatomic,strong)UIImageView *bottomLineView;

@end
@implementation WPMineInfomationCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier])
    {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        [self setupUI];
    }
    return self;
}

-(void)setupUI
{
    [self iconView];
    [self redPointLabel];
    [self titleLabel];
    [self infomationLabel];
    [self bottomLineView];
}

-(UIImageView *)iconView
{
    if (_iconView == nil)
    {
        _iconView = [[UIImageView alloc] init];
        _iconView.layer.cornerRadius = 20;
        _iconView.layer.masksToBounds = YES;
        [self.contentView addSubview:_iconView];
        
        [_iconView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.contentView).offset(15);
            make.top.equalTo(self.contentView).offset(12.5);
            make.width.height.mas_equalTo(40);
        }];
    }
    return _iconView;
}

-(UILabel *)redPointLabel
{
    if (_redPointLabel == nil)
    {
        _redPointLabel = [UILabel new];
        _redPointLabel.backgroundColor = RGB_COLOR(255, 102, 102);
        _redPointLabel.layer.cornerRadius = 5;
        _redPointLabel.layer.masksToBounds = YES;
        _redPointLabel.hidden = YES;
        
        [self.contentView addSubview:_redPointLabel];
        
        [_redPointLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.contentView).offset(47);
            make.top.equalTo(self.contentView).offset(14);
            make.width.height.mas_equalTo(10);
        }];
    }
    return _redPointLabel;
}

-(UILabel *)titleLabel
{
    if (_titleLabel == nil)
    {
        _titleLabel = [UILabel new];
        _titleLabel.font = [UIFont systemFontOfSize:15];
        _titleLabel.textColor = GLobalFontColor;
        [_titleLabel sizeToFit];
        [self.contentView addSubview:_titleLabel];
        
        [_titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.iconView.mas_right).offset(15);
            make.top.equalTo(self.contentView).offset(14);
        }];
    }
    return _titleLabel;
}

-(UILabel *)infomationLabel
{
    if (_infomationLabel == nil)
    {
        _infomationLabel = [UILabel new];
        _infomationLabel.textColor = GloballightFontColor;
        _infomationLabel.font = [UIFont systemFontOfSize:13];
        [_infomationLabel sizeToFit];
        [self.contentView addSubview:_infomationLabel];
        
        [_infomationLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.titleLabel);
            make.top.equalTo(self.titleLabel.mas_bottom).offset(10);
        }];
    }
    return _infomationLabel;
}

-(UIImageView *)bottomLineView
{
    if (_bottomLineView == nil)
    {
        _bottomLineView = [[UIImageView alloc] init];
        _bottomLineView.backgroundColor = GLobalLineColor;
        [self.contentView addSubview:_bottomLineView];
        
        [_bottomLineView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.contentView).offset(15);
            make.right.bottom.equalTo(self.contentView);
            make.height.mas_equalTo(0.5);
        }];
    }
    return _bottomLineView;
}

-(void)setIndexPath:(NSIndexPath *)indexPath
{
    _indexPath = indexPath;
    
//    if (indexPath.row == 0)
//    {
//        self.iconView.image = [UIImage imageNamed:@"systemInfomation"];
//        self.titleLabel.text = @"系统消息";
//        self.infomationLabel.text = @"暂无系统消息";
//    }
    if (indexPath.item == 0)
    {
        self.iconView.image = [UIImage imageNamed:@"privateInfo"];
        self.titleLabel.text = @"个人消息";
        
        if ([WPUserAccountViewModel sharedInstance].isNewPersonalInfo)
        {
            WPUserAccountViewModel *userAccountModel = [WPUserAccountViewModel sharedInstance];
            WPUserAccount *userAccount = userAccountModel.userAccount;
            NSString *privateInfomationArr = [documentPath stringByAppendingPathComponent:[NSString stringWithFormat:@"privateInfomationArr_%zd.plist",userAccount.user.id]];
            
            NSArray *arr = [NSKeyedUnarchiver unarchiveObjectWithFile:privateInfomationArr];
            self.infomationLabel.text = [[arr lastObject] title];
        }
        else
        {
            self.infomationLabel.text = @"暂无个人消息";
        }
        
        self.redPointLabel.hidden = ![WPUserAccountViewModel sharedInstance].isNewPersonalInfo;
    }
    else
    {
        self.iconView.image = [UIImage imageNamed:@"recommendInfo"];
        self.titleLabel.text = @"为您推荐";
        self.infomationLabel.text = @"暂无推荐消息";
        self.bottomLineView.hidden = YES;
    }
}
@end
